#ifndef SANDBOX_H
#define SANDBOX_H

#include "SmallEngine.h"
// #include "ScriptCommon.h"

class Sandbox : public CC::Layer
{
public:
	Sandbox(const std::string &name = "CCCity3d", CC::Scene* scene = nullptr);
	virtual ~Sandbox();

	virtual void OnAttach() override;
	virtual void OnDetach() override;

	void OnUpdate(CC::Timestep ts) override;
	virtual void OnImGuiRender() override;
	void OnEvent(CC::Event &e) override;
    
    
private:
	void OnWindowResize(CC::WindowResizeEvent &e);
	void OnMouseButtonPressed(CC::MouseButtonPressedEvent &e);
	void OnMouseButtonReleased(CC::MouseButtonReleasedEvent &e);
	void OnMouseButtonMoved(CC::MouseMovedEvent &e);
    void OnMouseScrolled(CC::MouseScrolledEvent &e);
	void OnKeyPressed(CC::KeyPressedEvent &e);
	void OnKeyReleased(CC::KeyReleasedEvent &e);
	void OnKeyWinPressed(CC::KeyWinEvent &e);
	void AddEntityScriptRecursively(CC::Entity *parent);

    void ShowProjectTreeTop();
    void ShowProjectTree(CC::Entity *parent);
    void ShowProperty();

    void HandleLeftButtonPressed();
    void HandleLeftButtonDouble();
    void HandleLeftButtonMoved();
    void HandleLeftButtonReleased();

    void HandleMidButtonPressed();
    void HandleMidButtonMoved();
    void HandleMidButtonReleased();

    void HandleRightButtonPressed();
    void HandleRightButtonMoved();
    void HandleRightButtonReleased();

    void AnimCallback();
    void DeleteObject(float x=0.0, float y = 0.0, float z = 0.0);

    void CreatePhotoBorderCmd();

    void HandleMouseMoved();

private:

	glm::vec4 m_SquareColor = {0.2f, 0.3f, 0.8f, 1.0f};
	glm::vec4 m_FontColor = {0.0f, 0.0f, 0.0f, 1.0f};
	glm::vec4 m_ClearColor = {0.0f, 0.0f, 0.0f, 0.0f};

	CC::Scene* m_Scene;
    CC::Entity* m_CurrentEntity;

	float m_MouseX = 0.0;
	float m_MouseY = 0.0;
	
    float m_LastMouseX = 0.0;
    float m_LastMouseY = 0.0;

    float m_LastDoubleMouseX = 0.0;
    float m_LastDoubleMouseY = 0.0;

    bool m_ButtonLeftPressed = false;    
    bool m_ButtonRightPressed = false;
    bool m_ButtonMidPressed = false;

    int m_ButtonLeftDouble = 0;
    float m_ButtonLeftDoubleTimeMax = 0.3;//s
    float m_ButtonLeftDoubleStartTime = 0.0;

    float m_AutoSaveTimeMax = 5.0;//s

    CC::Entity* box = NULL;
    CC::Entity* box_camera = NULL;
    CC::Entity* box_light = NULL;
    CC::Entity* camera3d = NULL;
  
    CC::Entity* light = NULL;
    CC::Entity* line = NULL;
    CC::Entity* ground = NULL;
    CC::Entity* windmill = NULL;
    CC::Entity* alchemist_s_house = NULL;
    CC::Entity* bakkery = NULL;
    CC::Entity* cloud = NULL;
    CC::Entity* Helicopter = NULL;
    CC::Entity* HelicopterYi = NULL;
    CC::Entity* hot_air_balloon = NULL;
    CC::Entity* wall_back = NULL;
   
    CC::Entity* image2dHelpTip = NULL;
    CC::Entity* imageCloud = NULL;

    CC::Entity* m_currentPickObject=NULL;
    CC::Entity* m_currentDeleteObject=NULL;
    CC::Entity* m_currentClickCarObject = NULL;
    int m_currentPickObjectSavedState;

    bool m_UseEditCamera = false;

    float m_CameraMoveSpeed = 0.1;
    float m_CameraScrollSpeed = 0.1;
    bool m_IsFirstPerson = false;

    CC::AnimationProperty* animationProperty;
    CC::AnimationProperty* animationProperty_windRotation;
    CC::AnimationProperty* animationProperty_boxcolor;
    CC::AnimationProperty* animationProperty_boxcolorRotation;
    CC::AnimationProperty* animationProperty_hot_air_balloonMove;
    CC::AnimationProperty* animationProperty_HelicopterMove;
    CC::AnimationProperty* animationProperty_HelicopterMove2;
    CC::AnimationProperty* animationProperty_HelicopterYiRotation;

    CC::AnimationProperty* animationProperty_CloudMove;

    float m_CameraAnimTime = 5000.0;

    bool m_HelpTipOn = false;
    bool m_LightOn = true;
    char m_HelpKeyCom[2] = { '0', '0' };

    glm::vec3 boxcolor;
    glm::vec3 boxRigitBodyRotation;
    float boxBlendIntensity;

    glm::vec3 cloudPos;

};

#endif